﻿<Page
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Converters="using:WinKee.Converters"
    x:Class="WinKee.Pages.MainPage"
    DataContext="{Binding RelativeSource={RelativeSource Mode=Self}}"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
    mc:Ignorable="d">
    <Page.Resources>
        <Converters:EmptyStringToVisibilityConverter x:Key="EmptyStringToVisibilityConverter"/>
    </Page.Resources>

    <Page.BottomAppBar>
        <CommandBar>
            <CommandBar.PrimaryCommands>
                <AppBarButton Label="Pick a DB" Command="{Binding SelectDatabaseCommand}" Visibility="{Binding IsPickFileVisible}">
                    <AppBarButton.Icon>
                        <SymbolIcon Symbol="OpenFile"/>
                    </AppBarButton.Icon>
                </AppBarButton>
                <AppBarButton Label="Add a KF" Command="{Binding AddKeyfileCommand}" Visibility="{Binding IsAddKeyfileVisible}">
                    <AppBarButton.Icon>
                        <SymbolIcon Symbol="Permissions"/>
                    </AppBarButton.Icon>
                </AppBarButton>
                <AppBarButton Label="Remove KF" Command="{Binding RemoveKeyfileCommand}" Visibility="{Binding IsRemoveKeyfileVisible}">
                    <AppBarButton.Icon>
                        <SymbolIcon Symbol="Clear"/>
                    </AppBarButton.Icon>
                </AppBarButton>
                <AppBarButton Label="Decrypt" Command="{Binding OpenCommand}" Visibility="{Binding IsUnlockVisible}">
                    <AppBarButton.Icon>
                        <SymbolIcon Symbol="Accept"/>
                    </AppBarButton.Icon>
                </AppBarButton>
                <AppBarButton Label="Cancel" Command="{Binding CancelCommand}" Visibility="{Binding IsCancelVisible}">
                    <AppBarButton.Icon>
                        <SymbolIcon Symbol="Cancel"/>
                    </AppBarButton.Icon>
                </AppBarButton>
            </CommandBar.PrimaryCommands>
        </CommandBar>
    </Page.BottomAppBar>
    
    <StackPanel Orientation="Vertical">
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="MainGroup">
                <VisualStateGroup.Transitions>
                    <VisualTransition GeneratedDuration="0">
                        <VisualTransition.GeneratedEasingFunction>
                            <BackEase EasingMode="EaseIn"/>
                        </VisualTransition.GeneratedEasingFunction>
                    </VisualTransition>
                </VisualStateGroup.Transitions>
                <VisualState x:Name="PickerState">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="textBlock">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="textBlock1">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="PasswordBox">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="DisplayPasswordCheckBox">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="PasswordTextBox">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="textBlock2">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="textBlock3">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="textBlock4">
                        	<DiscreteObjectKeyFrame KeyTime="0">
                        		<DiscreteObjectKeyFrame.Value>
                        			<Visibility>Collapsed</Visibility>
                        		</DiscreteObjectKeyFrame.Value>
                        	</DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="textBlock5">
                        	<DiscreteObjectKeyFrame KeyTime="0">
                        		<DiscreteObjectKeyFrame.Value>
                        			<Visibility>Collapsed</Visibility>
                        		</DiscreteObjectKeyFrame.Value>
                        	</DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="stackPanel">
                        	<DiscreteObjectKeyFrame KeyTime="0">
                        		<DiscreteObjectKeyFrame.Value>
                        			<Visibility>Collapsed</Visibility>
                        		</DiscreteObjectKeyFrame.Value>
                        	</DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="textBlock8">
                        	<DiscreteObjectKeyFrame KeyTime="0">
                        		<DiscreteObjectKeyFrame.Value>
                        			<Visibility>Collapsed</Visibility>
                        		</DiscreteObjectKeyFrame.Value>
                        	</DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="FileOpenStatePass">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="PasswordTextBox">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="textBlock4">
                        	<DiscreteObjectKeyFrame KeyTime="0">
                        		<DiscreteObjectKeyFrame.Value>
                        			<Visibility>Collapsed</Visibility>
                        		</DiscreteObjectKeyFrame.Value>
                        	</DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="textBlock5">
                        	<DiscreteObjectKeyFrame KeyTime="0">
                        		<DiscreteObjectKeyFrame.Value>
                        			<Visibility>Collapsed</Visibility>
                        		</DiscreteObjectKeyFrame.Value>
                        	</DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="textBlock7">
                        	<DiscreteObjectKeyFrame KeyTime="0">
                        		<DiscreteObjectKeyFrame.Value>
                        			<Visibility>Collapsed</Visibility>
                        		</DiscreteObjectKeyFrame.Value>
                        	</DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="listView">
                        	<DiscreteObjectKeyFrame KeyTime="0">
                        		<DiscreteObjectKeyFrame.Value>
                        			<Visibility>Visible</Visibility>
                        		</DiscreteObjectKeyFrame.Value>
                        	</DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>   
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="FileOpenStateText">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="PasswordBox">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="textBlock4">
                        	<DiscreteObjectKeyFrame KeyTime="0">
                        		<DiscreteObjectKeyFrame.Value>
                        			<Visibility>Collapsed</Visibility>
                        		</DiscreteObjectKeyFrame.Value>
                        	</DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="textBlock5">
                        	<DiscreteObjectKeyFrame KeyTime="0">
                        		<DiscreteObjectKeyFrame.Value>
                        			<Visibility>Collapsed</Visibility>
                        		</DiscreteObjectKeyFrame.Value>
                        	</DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="textBlock7">
                        	<DiscreteObjectKeyFrame KeyTime="0">
                        		<DiscreteObjectKeyFrame.Value>
                        			<Visibility>Collapsed</Visibility>
                        		</DiscreteObjectKeyFrame.Value>
                        	</DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="listView">
                        	<DiscreteObjectKeyFrame KeyTime="0">
                        		<DiscreteObjectKeyFrame.Value>
                        			<Visibility>Visible</Visibility>
                        		</DiscreteObjectKeyFrame.Value>
                        	</DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="DecryptingState">
                	<Storyboard>
                		<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="textBlock">
                			<DiscreteObjectKeyFrame KeyTime="0">
                				<DiscreteObjectKeyFrame.Value>
                					<Visibility>Collapsed</Visibility>
                				</DiscreteObjectKeyFrame.Value>
                			</DiscreteObjectKeyFrame>
                		</ObjectAnimationUsingKeyFrames>
                		<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="textBlock1">
                			<DiscreteObjectKeyFrame KeyTime="0">
                				<DiscreteObjectKeyFrame.Value>
                					<Visibility>Collapsed</Visibility>
                				</DiscreteObjectKeyFrame.Value>
                			</DiscreteObjectKeyFrame>
                		</ObjectAnimationUsingKeyFrames>
                		<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="PasswordBox">
                			<DiscreteObjectKeyFrame KeyTime="0">
                				<DiscreteObjectKeyFrame.Value>
                					<Visibility>Collapsed</Visibility>
                				</DiscreteObjectKeyFrame.Value>
                			</DiscreteObjectKeyFrame>
                		</ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="DisplayPasswordCheckBox">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="PasswordTextBox">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                		<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="textBlock2">
                			<DiscreteObjectKeyFrame KeyTime="0">
                				<DiscreteObjectKeyFrame.Value>
                					<Visibility>Collapsed</Visibility>
                				</DiscreteObjectKeyFrame.Value>
                			</DiscreteObjectKeyFrame>
                		</ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="textBlock3">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="textBlock4">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Visible</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="textBlock7">
                        	<DiscreteObjectKeyFrame KeyTime="0">
                        		<DiscreteObjectKeyFrame.Value>
                        			<Visibility>Collapsed</Visibility>
                        		</DiscreteObjectKeyFrame.Value>
                        	</DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="listView">
                        	<DiscreteObjectKeyFrame KeyTime="0">
                        		<DiscreteObjectKeyFrame.Value>
                        			<Visibility>Collapsed</Visibility>
                        		</DiscreteObjectKeyFrame.Value>
                        	</DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <StackPanel Margin="24,17,0,28">
            <TextBlock Text="WinKee" Style="{ThemeResource TitleTextBlockStyle}" Typography.Capitals="SmallCaps"/>
            <TextBlock Text="open file" Margin="0,12,0,0" Style="{ThemeResource HeaderTextBlockStyle}"/>
        </StackPanel>
       
        <TextBlock x:Name="textBlock7" Margin="5"  Style="{StaticResource BodyTextBlockStyle}">Pick a database to open by pressing the 'Pick a DB' button below.</TextBlock>
        <TextBlock x:Name="textBlock" Foreground="{StaticResource PhoneAccentBrush}" Margin="5,0" Text="{Binding SelectedFileName}" Style="{StaticResource BodyTextBlockStyle}" TextWrapping="Wrap" TextTrimming="CharacterEllipsis" FontSize="24" />
        <TextBlock x:Name="textBlock1" Margin="5,0" Text="{Binding SelectedFilePath}" TextWrapping="Wrap" TextTrimming="CharacterEllipsis" Style="{StaticResource BodyTextBlockStyle}" />

        <ListView Margin="5,5,5,0" x:Name="listView" ItemsSource="{Binding RecentFiles}" SelectionMode="None" ItemClick="RecentFiles_OnItemClick" MaxHeight="100" IsItemClickEnabled="True">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <TextBlock Foreground="{StaticResource PhoneAccentBrush}" Text="{Binding Item2}" Style="{StaticResource BodyTextBlockStyle}" />
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
        
        <TextBlock x:Name="textBlock4" Margin="5" Style="{StaticResource GroupHeaderTextBlockStyle}" Foreground="{StaticResource PhoneAccentBrush}">
            Decrypting database...
        </TextBlock>
        <TextBlock x:Name="textBlock5" Margin="5,10" Style="{StaticResource BodyTextBlockStyle}" TextWrapping="Wrap">
            This might take a lot of time, depending on the value of the "Number of key transformation rounds" setting in the database and the size of the database.
        </TextBlock>

        <TextBlock x:Name="textBlock8" Margin="5,10,5,0" TextWrapping="Wrap" Text="Estimated time to derive the decryption key is " Style="{StaticResource BodyTextBlockStyle}"/>
        <StackPanel Margin="5,0,5,10" x:Name="stackPanel" Orientation="Horizontal">
            <TextBlock Text="{Binding EstimatedOpeningTime}" Foreground="{StaticResource PhoneAccentBrush}" Margin="0,0,6,0" Style="{StaticResource BodyTextBlockStyle}"/>
            <TextBlock Text="seconds" Style="{StaticResource BodyTextBlockStyle}"/>
        </StackPanel>

        <PasswordBox KeyDown="PasswordBox_OnKeyDown" Password="{Binding Password, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" x:Name="PasswordBox" Header="Password" Margin="5,0"/>
        <TextBox KeyDown="PasswordBox_OnKeyDown" x:Name="PasswordTextBox" Text="{Binding Password, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Header="Password" Margin="5,0"/>
        <CheckBox Margin="5,0" x:Name="DisplayPasswordCheckBox" IsChecked="{Binding DisplayPassword, Mode=TwoWay}" Content="Display password" />
        
        <TextBlock Visibility="{Binding KeyfileName, Converter={StaticResource EmptyStringToVisibilityConverter}}" x:Name="textBlock2" Margin="5,0" Text="{Binding KeyfileName}" Foreground="{StaticResource PhoneAccentBrush}" TextWrapping="Wrap" TextTrimming="CharacterEllipsis" FontSize="24"/>
        <TextBlock Visibility="{Binding KeyfilePath, Converter={StaticResource EmptyStringToVisibilityConverter}}" x:Name="textBlock3" Margin="5,0" TextTrimming="CharacterEllipsis" Text="{Binding KeyfilePath}" FontSize="16"/>
    </StackPanel>
</Page>
